package com.lkd.shoppingcart.dao.impl;

import java.util.List;

import com.lkd.shoppingcart.dao.OrderDao;
import com.lkd.shoppingcart.entity.OrdersView;

public class OrderDaoImpl extends BaseDao implements OrderDao {

	@Override
	public int addOrder(String orderId, Integer userId) {
		String sql = "insert into orders(id, userId) values(?, ?)";
		return update(sql, orderId, userId);
	}

	@Override
	public int updateStatusById(String orderId, Integer status) {
		String sql = "update orders set status = ? where id = ?";
		return update(sql, status, orderId);
	}
	
	@Override
	public int updateStatus(Integer oldStatus, Integer newStatus) {
		String sql = "update orders set status = ? where status = ?";
		return update(sql, newStatus, oldStatus);
	}

	@Override
	public List<OrdersView> queryByUserId(Integer userId) {
		String sql = "select id, userId, status, crtTime, totalPrice from orders_view"
				+ " where userId = ? and status != 2 order by status desc";
		return queryForList(OrdersView.class, sql, userId);
	}

	@Override
	public List<OrdersView> queryAll() {
		String sql = "select id, userId, status, crtTime, totalPrice from orders_view"
				+ " where status != 2 order by status asc";
		return queryForList(OrdersView.class, sql);
	}

}
